package leetcode.n2022;

/**
 * https://leetcode-cn.com/problems/longest-nice-substring/
 * 1763. 最长的美好子字符串
 *
 * @Author: Chaos
 * @Date: 2022/2/01
 */
public class LongestNiceSubstring {

    /**
     * 感觉想是一个滑动窗口的题目
     */
    public String longestNiceSubstring(String s) {
//        int len = s.length() - 1;
//        while (len != 0) {
//
//            len--;
//        }

        if (s.length() < 2) {
            return "";
        }
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ((c <= 'Z' && !s.contains(String.valueOf((char) ((int) c + 32)))) || (c >= 'a' && !s.contains(String.valueOf((char) ((int) c - 32))))) {
                String s1 = longestNiceSubstring(s.substring(0, i));
                String s2 = longestNiceSubstring(s.substring(i + 1));
                if (s1.length() >= s2.length()) {
                    return s1;
                }
                return s2;
            }
        }
        return s;

    }

    public static void main(String[] args) {
        String s = "CCCbaAZzbBfsdfsdz";

        System.out.println(new LongestNiceSubstring().longestNiceSubstring(s));
    }
}
